package com.insigma.business.qrcode.common.vo;


import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

public class BaseDTO<PK extends Serializable, CID extends Serializable, MID extends Serializable> extends ToString {
    private static final long serialVersionUID = 1L;
    private PK id;
    private boolean deleted = false;
    private String creatorType;
    private CID creatorId;
    private String modifierType;
    private MID modifierId;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createDatetime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date modifyDatetime;

    @ApiModelProperty("创建时间时分秒格式字符串")
    private String createDatetimeStr;

    @ApiModelProperty("修改时间时分秒格式字符串")
    private String modifyDatetimeStr;

    public BaseDTO() {
    }

    public PK getId() {
        return this.id;
    }

    public boolean isDeleted() {
        return this.deleted;
    }

    public String getCreatorType() {
        return this.creatorType;
    }

    public CID getCreatorId() {
        return this.creatorId;
    }

    public String getModifierType() {
        return this.modifierType;
    }

    public MID getModifierId() {
        return this.modifierId;
    }

    public Date getCreateDatetime() {
        return this.createDatetime;
    }

    public Date getModifyDatetime() {
        return this.modifyDatetime;
    }

    public void setId(PK id) {
        this.id = id;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public void setCreatorType(String creatorType) {
        this.creatorType = creatorType;
    }

    public void setCreatorId(CID creatorId) {
        this.creatorId = creatorId;
    }

    public void setModifierType(String modifierType) {
        this.modifierType = modifierType;
    }

    public void setModifierId(MID modifierId) {
        this.modifierId = modifierId;
    }

    public void setCreateDatetime(Date createDatetime) {
        this.createDatetime = createDatetime;
        if(Objects.nonNull(createDatetime)){
            setCreateDatetimeStr(DateFormatUtils.format(createDatetime,"yyyy-MM-dd HH:mm:ss"));
        }
    }

    public void setModifyDatetime(Date modifyDatetime) {
        this.modifyDatetime = modifyDatetime;
        if(Objects.nonNull(modifyDatetime)){
            setModifyDatetimeStr(DateFormatUtils.format(modifyDatetime,"yyyy-MM-dd HH:mm:ss"));
        }
    }

    public String getCreateDatetimeStr() {
        return createDatetimeStr;
    }

    public void setCreateDatetimeStr(String createDatetimeStr) {
        this.createDatetimeStr = createDatetimeStr;
    }

    public String getModifyDatetimeStr() {
        return modifyDatetimeStr;
    }

    public void setModifyDatetimeStr(String modifyDatetimeStr) {
        this.modifyDatetimeStr = modifyDatetimeStr;
    }
}
